package pers.mihao.quickstream.publish.strategy.filter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pers.mihao.quickstream.publish.strategy.context.ChooseContext;
import pers.mihao.quickstream.publish.strategy.dto.ChooseAccount;
import pers.mihao.quickstream.publish.strategy.dto.ChooseAccountScore;
import pers.mihao.quickstream.publish.strategy.filter.factory.DefaultAccountFilterFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 一个平台只选一个账户过滤
 *
 * @author mihao
 * @since 2024/11/25
 */
@Component("accountFilter")
public class AccountFilterFace implements AccountFilter {

    @Autowired(required = false)
    List<AccountFilter> accountFilters;

    @Override
    public boolean isMatch(ChooseContext chooseContext) {
        return false;
    }

    @Override
    public List<ChooseAccount> accountFilter(ChooseContext chooseContext, List<ChooseAccountScore> accountScores) {
        AccountFilter filterChain = new DefaultAccountFilterFactory(accountFilters)
                .buildFilterChain(chooseContext);
        if (filterChain == null) {
            return new ArrayList<>();
        }
        return filterChain.accountFilter(chooseContext, accountScores);
    }


}
